﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace 超市收银系统
{
    class ProductFather
    {
        public double Price
        {
            get;
            set;
        }
        public string Name
        {
            get;
            set;
        }
        public string ID
        {
            get;
            set;
        }
        public ProductFather() { }
        public ProductFather(string id,string name,double price)
        {
            this.Price = price;
            this.Name = name;
            this.ID = id;
        }
    }

    #region 商品货架、购物车结构

    public class Product
    {
        /// <summary>
        /// 商品名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 商品编号
        /// </summary>
        public string ID { get; set; }
        /// <summary>
        /// 商品价格
        /// </summary>
        public double Price { get; set; }
        /// <summary>
        /// 单位
        /// </summary>
        public string Unit { get; set; }

        public Product()
        {

        }

        protected Product(string name, string iD, double price, string unit)
        {
            Name = name;
            ID = iD;
            Price = price;
            Unit = unit;
        }
    }

    /// <summary>
    /// 商品货架
    /// </summary>
    public class ProductShelve
    {
        public Product TheProduct { get; set; }
        public double Count { get; set; }

        public ProductShelve(Product theProduct, double count)
        {
            this.TheProduct = theProduct;
            this.Count = count;
        }

        public void Add(double count)
        {
            this.Count += count;
        }

        public void Remove(double count)
        {
            if (count > this.Count)
            {
                Console.WriteLine("商品售出数量超过库存，无法销售！请检查商品。");
                return;
            }
            this.Count -= count;
        }
    }

    /// <summary>
    /// 商品出售单品类
    ///     单类有折扣
    /// </summary>
    public class ProductCartSub
    {
        public double SaleCount { get; set; }

        public Product TheProduct { get; set; }

        public double TotalPrice { get { return this.TheProduct.Price * this.SaleCount; } }

        public double DiscountTotalPrice { get { return this.TotalPrice; } }

        public ProductCartSub(Product theProduct, double count)
        {
            this.TheProduct = theProduct;
            this.SaleCount = count;
        }

        public void SetDiscount()
        {

        }
    }

    /// <summary>
    /// 商品出售总单 
    ///     可能有会员折上折，或者其他优惠
    /// </summary>
    public class ProductCart : List<ProductCartSub>
    {
        public double TotalPrice { get { return this.Sum(p => p.TotalPrice); } }

        public double DiscountTotalPrice { get { return this.Sum(p => p.DiscountTotalPrice); } }

        public double DisDiscountTotalPrice { get { return this.DiscountTotalPrice; } }

        public void SetDiscount()
        {

        }

        /// <summary>
        /// 结账
        ///     货架数量修改
        ///     打印账单小票
        /// </summary>
        public void CheckOut()
        {

        }
    } 
    #endregion
}
